package com.yy.cloud.api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @date 2024/5/6
 */
@RestController
@RefreshScope // 实现配置动态刷新并赋值给变量
@Slf4j
public class ConfigTestController {

    @Value("${activitySwitch.val:false}")
    private boolean activitySwitch; // 实现业务功能的开关，该属性配置在配置中心的配置文件里

    @Value("${lovesong.val}")
    private String loveSong; // 多配置读取

    @GetMapping("/configTest")
    public String configTest() {
        log.info("lovesong.val = {}", loveSong);
        return activitySwitch ? "活动页面渲染所需数据" : "活动未开始！";
    }
}
